def radix_sort(array=[]):
    max_digit = 0  # 最大为几位数值
    for a in array:
        if len(str(a)) > max_digit:
            max_digit = len(str(a))
    mod = 10
    dev = 1
    for i in range(max_digit):
        bucket_list = [None] * 10
        for j in range(len(array)):
            var = array[j]
            bucket_index = (var % mod) // dev
            """
            这个地方要用pop()函数，移除列表中的一个元素（默认最后一个元素），
            并且返回该元素的值，要不然下面用insert()函数时，bucuket_list的长
            度一直在递增
            """
            bucket=bucket_list.pop(bucket_index)
            if bucket is None:
                bucket = []
            bucket.append(var)
            """这里用list的insert函数，插入对应索引位置"""
            bucket_list.insert(bucket_index,bucket)
        var = 0
        for bucket_index in range(len(bucket_list)):
            bucket = bucket_list[bucket_index]
            if bucket:
                for k in range(len(bucket)):
                    array[var] = bucket[k]
                    var += 1
        mod *= 10
        dev *= 10
    return  array





array=[4724,32433,8672,1893,2703,3417,55034,39832]

radix_sort(array)

print(array)
